home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 3 / Amiga Format CD03 (1996-07-04)(Future Publishing)(GB)(Track 1 of 6)[!][issue 1996-08].iso / comms / netsoftware / nethandler.lha / NetHandler / debug.c < prev    next >
C/C++ Source or Header  |  1989-09-16  |  4KB  |  219 lines

  1. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  2. /* |_o_o|\\ Copyright (c) 1987 The Software Distillery.  All Rights Reserved */
  3. /* |. o.| || This program may not be distributed without the permission of   */
  4. /* | .  | || the author.                                           BBS:      */
  5. /* | o  | ||   John Toebes    Dave Baker                     (919)-471-6436  */
  6. /* |  . |//                                                                  */
  7. /* ======                                                                    */
  8. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  9. #define NETCOMMON
  10. #include "netcomm.h"
  11. #include "proto.h"
  12. #include <ctype.h>
  13.  
  14. #if PARANOID
  15. int paranoid = 1;
  16. #endif
  17.  
  18. #if CPR
  19.  
  20. BPTR debuglog = NULL;
  21. extern char *dbgwind;
  22. static void makehex U_ARGS((char *, char *));
  23. static void termlog U_ARGS((void));
  24. static void xclose U_ARGS((BPTR));
  25. static BPTR xopen  U_ARGS((char *));
  26.  
  27. BPTR initdebug(fh)
  28. BPTR fh;
  29. {
  30.    BPTR ofh;
  31. #if DEBUG
  32.    ofh = debuglog;
  33.    if(!(debuglog = fh)) debuglog = xopen(dbgwind);
  34. #else
  35.    ofh = NULL;
  36. #endif
  37.  
  38.    BUG(("DEBUGGING INITIALIZED\n"));
  39.  
  40.    return(ofh);
  41. }
  42.  
  43. void termdebug()
  44. {
  45.    BUG(("Closing log\n"));
  46.    BUGGETC
  47.  
  48.    if(debuglog) xclose(debuglog);
  49.    debuglog = NULL;
  50. }
  51.  
  52. BPTR xopen(name)
  53. char *name;
  54. {
  55.    return(Open(name, 1006));
  56. }
  57.  
  58. void xclose(log)
  59. BPTR log;
  60. {
  61.    long args[1];
  62.    struct FileHandle *fh;
  63.  
  64.    if(!log) return;
  65.  
  66.    fh = (struct FileHandle *)BADDR(log);
  67.    args[0] = (long)fh->fh_Arg1;
  68.    sendpkt(fh->fh_Type,ACTION_END,args,1);
  69. }
  70.  
  71. void xwrite(str,len)
  72. char *str;
  73. int len;
  74. {
  75.    long args[3];
  76.    struct FileHandle *fh;
  77.  
  78.    if(!debuglog) return;
  79.  
  80.    fh = (struct FileHandle *)BADDR(debuglog);
  81.    args[0] = (long)fh->fh_Arg1;
  82.    args[1] = (long)str;
  83.    args[2] = (long)len;
  84.    sendpkt(fh->fh_Type,ACTION_WRITE,args,3);
  85. }
  86.  
  87. #define CRMSG "Hit RETURN to continue: "
  88.  
  89. void xgetcr()
  90. {
  91.    long args[3];
  92.    struct FileHandle *fh;
  93.    char stuff[10];
  94.  
  95.    if(!debuglog) return;
  96.  
  97.    xwrite(CRMSG, strlen(CRMSG));
  98.    fh = (struct FileHandle *)BADDR(debuglog);
  99.    args[0] = (long)fh->fh_Arg1;
  100.    args[1] = (long)stuff;
  101.    args[2] = 9L;
  102.    sendpkt(fh->fh_Type,ACTION_READ,args,3);
  103. }
  104.  
  105. void myprintf(str,p1,p2,p3,p4,p5,p6,p7,p8,p9)
  106. char *str;
  107. char *p1,*p2,*p3,*p4,*p5,*p6,*p7,*p8,*p9;
  108. {
  109.    char buf[128];
  110.    int len;
  111.  
  112.    if(!debuglog) return;
  113.  
  114.    len = sprintf(buf,str,p1,p2,p3,p4,p5,p6,p7,p8,p9);
  115.    if (len>128) len = 128;
  116.    xwrite(buf,len);
  117. }
  118.  
  119. void myputbstr(str, name)
  120. char *str;
  121. char *name;
  122. {
  123.    int len;
  124.  
  125.    if(!debuglog) return;
  126.  
  127.    xwrite(str, strlen(str));
  128.    len = *name++;
  129.    xwrite(name, len);
  130.    xwrite("\n", 1);
  131. }
  132.  
  133. void myputlstr(str, name, len)
  134. char *str;
  135. char *name;
  136. int len;
  137. {
  138.    if(!debuglog) return;
  139.  
  140.    xwrite(str, strlen(str));
  141.    xwrite(name, len);
  142.    xwrite("\n", 1);
  143. }
  144.  
  145. static void makehex(s, h)
  146. char *s;
  147. char *h;
  148. {
  149.    int i;
  150.    static char *digits = "0123456789ABCDEF";
  151.  
  152.    if(!debuglog) return;
  153.  
  154.    for(i=0; i<8; i+=2)
  155.    {
  156.       h[i]   = digits[ (s[i/2] & 0xf0) >> 4 ];
  157.       h[i+1] = digits[ (s[i/2] & 0x0f)      ];
  158.    }
  159. }
  160.  
  161. void mydump(s, l)
  162. unsigned char *s;
  163. int l;
  164. {
  165.    int i, j;
  166.    char h[9];
  167.  
  168.    if(!debuglog) return;
  169.  
  170.    h[8] = 0;
  171.    BUG(("Dumping %ld bytes starting at addr %08.8x\n", l, s));
  172.    for(i=0; i<l; i+=16)
  173.    {
  174.       BUG(("%08.8lx: ", i));
  175.  
  176.       for(j=0; j<16; j+=4)
  177.       {
  178.          makehex(&s[i+j], h);
  179.          if(i+j<l){BUG(("%8.8s ", h));}
  180.          else     {BUG(("         "));}
  181.       }
  182.  
  183.       for(j=0; j<16 && i+j<l; j++)
  184.          if(isprint(s[i+j])) {BUG(("%c", s[i+j]));}
  185.          else {BUG(("."));}
  186.  
  187.       BUG(("\n"));
  188.    }
  189. }
  190.  
  191. void cprwait(global)
  192. GLOBAL global;
  193. {
  194.    int i, j, oldpri;
  195.  
  196.    if(!request(global, REQ_GENERAL, "Loop for debug?")) return;
  197.    
  198.    BUG(("********* DEBUG WAIT LOOP ***********\n"))
  199.    BUG(("******* CATCH TASK WITH CPR *********\n"))
  200.    oldpri = SetTaskPri(FindTask(NULL), -20);
  201.    i=1;
  202.    
  203.    /* This loop will go until you set i to 0 with CPR */
  204.    while(i)
  205.    {
  206.       BUG(("."))
  207.       for(j=0; 
  208.           i && j<100000; 
  209.           j++);
  210.    }
  211.  
  212.    SetTaskPri(FindTask(NULL), oldpri);
  213.    return;
  214. }
  215. #else
  216. void cprwait(global)
  217. GLOBAL global;
  218. {return;}
  219. #endif CPR